#include "Method.h"
#include <iomanip>

double func1(double x){
  return sin(x/2) - 1;
}

double func2(double x){
  return exp(x) - tan(x);
}

double func3(double x){
  return x*x*x - 12*x*x + 3*x + 1;
}

int main(int argc, char* argv[]){
  double (*pf[3])(double) = {&func1,&func2,&func3};
  Secant<double> SCSolver(50,1e-6,pf[0],0,PI/2,1e-8);
  double result,error = 0;
  result = SCSolver.solve();
  error = (*pf[0])(result);
  cout << "Problem 1 : " << endl;
  cout << "With initial 0 and pi/2: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
  SCSolver.set_init0(-2*PI);
  SCSolver.set_init1(-1.5*PI);
  result = SCSolver.solve();
  error = (*pf[0])(result);
  cout << "With initial -2pi and -3pi/2: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
  SCSolver.set_function(pf[1]);
  SCSolver.set_init0(1);
  SCSolver.set_init1(1.4);
  result = SCSolver.solve();
  error = (*pf[1])(result);
  cout << "Problem 2 : " << endl;
  cout << "With initial 1 and 1.4: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
  SCSolver.set_init0(-3);
  SCSolver.set_init1(-3.2);
  result = SCSolver.solve();
  error = (*pf[1])(result);
  cout << "With initial -3 and -3.2: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
  SCSolver.set_function(pf[2]);
  SCSolver.set_init0(0);
  SCSolver.set_init1(-0.5);
  result = SCSolver.solve();
  error = (*pf[2])(result);
  cout << "Problem 3 : " << endl;
  cout << "With initial 0 and -0.5: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
  SCSolver.set_init0(0);
  SCSolver.set_init1(0.5);
  result = SCSolver.solve();
  error = (*pf[2])(result);
  cout << "With initial 0 and 0.5: x = " << setprecision(8) << result << ", absolute error r = " << error << endl;
}
